package com.meng.mini.spring.beans;

import com.meng.mini.spring.beans.ArgumentValues;
import com.meng.mini.spring.beans.PropertyValues;
import lombok.Getter;
import lombok.Setter;

/**
 * @author Mr.Still
 * @version 1.0.0 bean管理对象
 * @date 2024-01-15 16:54
 **/
public class BeanDefinition {
    String SCOPE_SINGLETON = "singleton";
    String SCOPE_PROTOTYPE = "prototype";

    /**
     * 是否懒加载
     */
    @Getter
    @Setter
    private boolean lazyInit = false;

    @Getter
    private String[] dependsOn;

    @Getter
    private ArgumentValues constructorArgumentValues;

    @Getter
    private PropertyValues propertyValues;

    /**
     * 初始化方法name
     */
    @Getter
    @Setter
    private String initMethodName;

    private volatile Object beanClass;

    /**
     * 类名称
     */
    @Setter
    @Getter
    private String id;

    /**
     * 类路径
     */
    @Setter
    @Getter
    private String className;

    /**
     * 默认作用域
     */
    @Getter
    @Setter
    private String scope=SCOPE_SINGLETON;

    public BeanDefinition(String id, String className) {
        this.id = id;
        this.className = className;
    }

    public boolean hasBeanClass() {
        return (this.beanClass instanceof Class);
    }

    public void setBeanClass(Class<?> beanClass) {
        this.beanClass = beanClass;
    }

    public Class<?> getBeanClass(){

        return (Class<?>) this.beanClass;
    }

    public boolean isSingleton() {
        return SCOPE_SINGLETON.equals(scope);
    }

    public boolean isPrototype() {
        return SCOPE_PROTOTYPE.equals(scope);
    }

    public void setDependsOn(String... dependsOn) {
        this.dependsOn = dependsOn;
    }

    public void setConstructorArgumentValues(ArgumentValues constructorArgumentValues) {
        this.constructorArgumentValues =
                (constructorArgumentValues != null ? constructorArgumentValues : new ArgumentValues());
    }

    public boolean hasConstructorArgumentValues() {
        return !this.constructorArgumentValues.isEmpty();
    }
    public void setPropertyValues(PropertyValues propertyValues) {
        this.propertyValues = (propertyValues != null ? propertyValues : new PropertyValues());
    }

}